package com.sali.b_design_pattern.a_simple_factory_pattern.lesson_02.mode.factory;

import com.sali.b_design_pattern.a_simple_factory_pattern.lesson_02.mode.product.IUserVipService;
import com.sali.b_design_pattern.a_simple_factory_pattern.lesson_02.mode.product.NormalUserVipService;
import com.sali.b_design_pattern.a_simple_factory_pattern.lesson_02.mode.product.SvipUserVipService;
import com.sali.b_design_pattern.a_simple_factory_pattern.lesson_02.mode.product.YearUesrVipService;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @description: 简单工厂设计模式，解决一类产品对象的管理
 * 注册表优化
 * @date: 2022/11/13 19:28.
 * @version: 1.0
 */
public class UserVipServiceFactory {

    /**
     * description: 注册表的单例方式，也就是springIOC的原理
     **/
    static Map<String, IUserVipService> map = new ConcurrentHashMap<>();

    static {
        map.put("1", new NormalUserVipService());
        map.put("2", new YearUesrVipService());
        map.put("3", new SvipUserVipService());
    }

    public static IUserVipService getInstance(Integer vip) {
        return map.get(String.valueOf(vip));
    }

}
